<!DOCTYPE html>
<html>

<head>
  <title>WebSocket Client A</title>
  <script>
    let passObj = {
      clientId: '',
      message: ''
    };
    const ws = new WebSocket('ws://localhost:3000?clientId=AAAAA');

    ws.onopen = function () {
      console.log('客户端 A 已连接到 WebSocket 服务器');
    };

    ws.onmessage = function (event) {
      console.log('客户端 A 收到消息:', event);
      console.log(JSON.parse(event.data));
    };

    ws.onclose = function () {
      console.log('客户端 A 关闭连接');
    };

    function sendMessage() {
      passObj.message = document.getElementById('message-input').value;
      ws.send(JSON.stringify(passObj));
    }

    function joinB(value) {
      passObj.clientId = value
      console.log(passObj);
    }
  </script>
</head>

<body>
  <div id="app">
    <h1>WebSocket Client A</h1>
    <input type="text" id="message-input" placeholder="输入消息">
    <button onclick="sendMessage()">发送消息</button>
    <button onclick="joinB('BBBBB')">和b聊天</button>
  </div>

</body>

</html>